#include<iostream>
#include<cstdio>
using namespace std;
int gcd(int a, int b)
{
	return b == 0 ? gcd(b, a % b) : a;
}
int main()
{
	int t;
	scanf("%d", &t);
	while (t--) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a == b) {
			cout << "3  1" << endl;
			continue;
		}
		int ma = max(a, b);
		int mi = a + b - ma;
		if (ma % mi != 0) {
			cout << "0 0" << endl;
			continue;
		}
		else {
			int k = ma / mi;
			int res = 0;
			int flag = 0;
			int idx = 0;
			for (int i = 2; i * i <= k; i++) {
				while (k % i == 0) {
					res++;
					k /= i;
					if (k == 1) {
						flag = 1;
						idx = i;
					}
				}
			}
			if (flag) {
				cout << res << " " << idx << endl;
			}
			else {
				cout << "0 0" << endl;
			}
		}
	}
	return 0;
}